package org.rsbot.event.impl;

import java.awt.Color;
import java.awt.FontMetrics;
import java.awt.Graphics;
import java.awt.Point;
import org.rsbot.bot.Bot;
import org.rsbot.client.Client;
import org.rsbot.client.Node;
import org.rsbot.client.RSNPCNode;
import org.rsbot.event.listeners.PaintListener;
import org.rsbot.script.methods.Calculations;
import org.rsbot.script.methods.Game;
import org.rsbot.script.methods.MethodContext;
import org.rsbot.script.methods.Nodes;
import org.rsbot.script.wrappers.RSNPC;

public class DrawNPCs
  implements PaintListener
{
  private MethodContext ctx;

  public DrawNPCs(Bot paramBot)
  {
    this.ctx = paramBot.getMethodContext();
  }

  public void onRepaint(Graphics paramGraphics) {
    if (!this.ctx.game.isLoggedIn()) {
      return;
    }
    FontMetrics localFontMetrics = paramGraphics.getFontMetrics();
    for (int k : this.ctx.client.getRSNPCIndexArray()) {
      Node localNode = this.ctx.nodes.lookup(this.ctx.client.getRSNPCNC(), k);
      if ((localNode == null) || (!(localNode instanceof RSNPCNode))) {
        continue;
      }
      RSNPC localRSNPC = new RSNPC(this.ctx, ((RSNPCNode)localNode).getRSNPC());
      Point localPoint = this.ctx.calc.tileToScreen(localRSNPC.getLocation(), localRSNPC.getHeight() / 2);
      if (!this.ctx.calc.pointOnScreen(localPoint)) {
        continue;
      }
      paramGraphics.setColor(Color.RED);
      paramGraphics.fillRect((int)localPoint.getX() - 1, (int)localPoint.getY() - 1, 2, 2);
      String str = "" + localRSNPC.getID();
      paramGraphics.setColor(localRSNPC.isMoving() ? Color.green : localRSNPC.isInCombat() ? Color.red : Color.WHITE);
      paramGraphics.drawString(str, localPoint.x - localFontMetrics.stringWidth(str) / 2, localPoint.y - localFontMetrics.getHeight() / 2);

      if ((localRSNPC.getAnimation() != -1) || (localRSNPC.getGraphic() != -1)) {
        str = "(A: " + localRSNPC.getAnimation() + " | G: " + localRSNPC.getGraphic() + ")";
        paramGraphics.drawString(str, localPoint.x - localFontMetrics.stringWidth(str) / 2, localPoint.y - localFontMetrics.getHeight() * 3 / 2);
      }
    }
  }
}